﻿using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Subgurim.Controles;
using Data;
using Business;

namespace GestorEventos
{
    public partial class showPalco : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Request.QueryString["palcoID"] != null)
            {
                int palcoID = Convert.ToInt32(Request.QueryString["palcoID"].ToString());

                GMap1.enableGoogleBar = true;
                GMap1.enableHookMouseWheelToZoom = true;
                GMap1.enableGKeyboardHandler = true;
                GMap1.addControl(new GControl(GControl.extraBuilt.TextualCoordinatesControl));
                GMap1.addControl(new GControl(GControl.preBuilt.MapTypeControl, new GControlPosition(GControlPosition.position.Bottom_Right)));
                GMap1.addControl(new GControl(GControl.preBuilt.LargeMapControl, new GControlPosition(GControlPosition.position.Top_Right)));
                Palco p = new Palco();
                p = p.getPalcoByID(palcoID);
                int statusPalco = p.getStatus();
                
                
                
                this.idPalcohf.Value = "20";
                this.Nomelbl2.Text = p.getNomePalco();
                this.Localidadelbl2.Text = p.getLocalidade();
                this.Categorialbl2.Text = p.getCategoria();
                this.Rualbl2.Text = p.getRua();
                this.Desclbl2.Text = p.getDescricaoPalco();
                this.CodPostallbl2.Text = p.getCodPostal();
                GMarker marker = new GMarker(new GLatLng(p.getCoordLat(), p.getCoordLon()));
                GMap1.addGMarker(marker);
                GMap1.setCenter(new GLatLng(p.getCoordLat(), p.getCoordLon()), 16);


                if (Session["userStatus"] != null)
                {
                    int status = Convert.ToInt32(Session["userStatus"].ToString());

                    // Utilizador
                    if (status >= 1)
                    {
                        if (statusPalco == 1)
                        {
                            HyperLinkEditar.Text = "Editar Palco";
                            HyperLinkEditar.NavigateUrl = "editPalco.aspx?palcoID=" + palcoID + "";
                            if (statusPalco != 2)
                            {
                                LinkButtonDenunciar.Text = "Marcar para Revisão";
                            }

                        }
                    }

                    // Moderador
                    if (status > 1)
                    {
                        if (statusPalco != 0)
                        {
                            HyperLinkEditar.Text = "Editar Palco";
                            LinkButtonRemover.Text = "Remover";
                        }
                        if (statusPalco == 0)
                        {
                            HyperLinkEditar.Text = "Editar Palco";
                            LinkButtonRemover.Text = "Activar Palco";
                        }

                        if (statusPalco == 2)
                        {
                            HyperLinkEditar.Text = "Editar Palco";
                            LinkButtonDenunciar.Text = "Marcar como revisto";
                        }

                    }

                    // Administrador

                }


            }
            else {
                Response.Redirect("Default.aspx");

            }
        }

        protected string GMap1_Click(object s, Subgurim.Controles.GAjaxServerEventArgs e)
        {
            return default(string);
        }


        protected void Editarb_Click(object sender, EventArgs e)
        {
            Session["idPalco"] = idPalcohf.Value;

            Response.Redirect("editPalco.aspx");
        }


        public void setDenunciado(Object o, EventArgs e)
        {
            bool value = false;
            int palcoID;
            if (Request.QueryString["palcoID"] != null)
            {
                palcoID = Convert.ToInt32(Request.QueryString["palcoID"].ToString());

                Palco p = new Palco();
                Palco palco = p.getPalcoByID(palcoID);


                int statusPalco = palco.getStatus();

                

                if (statusPalco == 1)
                {
                    value = palco.setEstadoPalco(2);
                    Response.Redirect("showPalco.aspx?palcoID=" + palcoID + "");
                }

                if (statusPalco == 2)
                {
                    value = palco.setEstadoPalco(1);
                    Response.Redirect("showPalco.aspx?palcoID=" + palcoID + "");

                }
            }
            else
            {
                Response.Redirect("Default.aspx");

            }

        }

        public void setRemovido(Object o, EventArgs e)
        {
            bool value = false;
            int palcoID;

            if (Request.QueryString["palcoID"] != null)
            {
                palcoID = Convert.ToInt32(Request.QueryString["palcoID"].ToString());


                Palco p = new Palco();
                Palco palco = p.getPalcoByID(palcoID);



                int statusPalco = palco.getStatus();
                
                if (statusPalco == 0)
                {
                    value = palco.setEstadoPalco(1);
                    
                }

                if (statusPalco == 1)
                {
                    value = palco.setEstadoPalco(0);
                    

                }
                if (value)
                {
                    Response.Redirect("showPalco.aspx?palcoID=" + palcoID + "");

                }
                else Response.Redirect("showPalco.aspx?palcoID=" + palcoID + "");



            }

        }


    }
}
